package cn.kgc.mes.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.kgc.mes.common.annotation.Log;
import cn.kgc.mes.common.core.controller.BaseController;
import cn.kgc.mes.common.core.domain.AjaxResult;
import cn.kgc.mes.common.enums.BusinessType;
import cn.kgc.mes.domain.MaintenRecord;
import cn.kgc.mes.service.IMaintenRecordService;
import cn.kgc.mes.common.utils.poi.ExcelUtil;
import cn.kgc.mes.common.core.page.TableDataInfo;

/**
 * 设备保养记录Controller
 * 
 * @author ruoyi
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/MaintenRecord/MaintenRecord")
public class MaintenRecordController extends BaseController
{
    @Autowired
    private IMaintenRecordService maintenRecordService;

    /**
     * 查询设备保养记录列表
     */
//    @PreAuthorize("@ss.hasPermi('MaintenRecord:MaintenRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaintenRecord maintenRecord)
    {
        startPage();
        List<MaintenRecord> list = maintenRecordService.selectMaintenRecordList(maintenRecord);
        return getDataTable(list);
    }

    /**
     * 导出设备保养记录列表
     */
//    @PreAuthorize("@ss.hasPermi('MaintenRecord:MaintenRecord:export')")
    @Log(title = "设备保养记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintenRecord maintenRecord)
    {
        List<MaintenRecord> list = maintenRecordService.selectMaintenRecordList(maintenRecord);
        ExcelUtil<MaintenRecord> util = new ExcelUtil<MaintenRecord>(MaintenRecord.class);
        util.exportExcel(response, list, "设备保养记录数据");
    }

    /**
     * 获取设备保养记录详细信息
     */
//    @PreAuthorize("@ss.hasPermi('MaintenRecord:MaintenRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(maintenRecordService.selectMaintenRecordByRecordId(recordId));
    }

    /**
     * 新增设备保养记录
     */
//    @PreAuthorize("@ss.hasPermi('MaintenRecord:MaintenRecord:add')")
    @Log(title = "设备保养记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaintenRecord maintenRecord)
    {
        return toAjax(maintenRecordService.insertMaintenRecord(maintenRecord));
    }

    /**
     * 修改设备保养记录
     */
//    @PreAuthorize("@ss.hasPermi('MaintenRecord:MaintenRecord:edit')")
    @Log(title = "设备保养记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaintenRecord maintenRecord)
    {
        return toAjax(maintenRecordService.updateMaintenRecord(maintenRecord));
    }

    /**
     * 删除设备保养记录
     */
//    @PreAuthorize("@ss.hasPermi('MaintenRecord:MaintenRecord:remove')")
    @Log(title = "设备保养记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(maintenRecordService.deleteMaintenRecordByRecordIds(recordIds));
    }
}
